package br.com.NoTraffic.decoder;

public class Decoder {

	String HTML;

	public Decoder(String html) {
		HTML = html;
	}

	public String getAllInf(String Street) {
		if (HTML != null && Street != null) {
			String HTMLIndex = Street;
			int index = HTML.indexOf(HTMLIndex);
			if (index == -1) {
				return null;
			}
			int beginningIndex = index + Street.length() + 40;
			String newHtml = HTML.substring(beginningIndex);
			newHtml = newHtml.substring(newHtml.indexOf('>') + 1, newHtml
					.indexOf('<'));
			newHtml = newHtml.replaceAll("Cur speed: ", "Sp:");
			newHtml = newHtml.replaceAll("Delay: ", "Dl:");
			newHtml = newHtml.replaceAll(" ", "");
			newHtml = newHtml.replace('|', ' ');
			return newHtml;
		} else {
			return null;
		}
	}

	public static String shortTerm(String street) {
		if(street == null){
			return null;
		}
		
		if (street.contains("btwn")) {
			street = street.substring(0, street.indexOf("btwn") - 1);
			
		}
		if (street.length() > 25) {
			street = street.substring(0, street.lastIndexOf(' '));
		}
		return street;
	}
}
